// 攻击双爆增伤数值平衡

// attack   criticalStrike  dmgAdd
const enmus = {
    criticalRate: "暴击",
    criticalCtrike: "爆伤",
    dmgAdd: "增伤",
    attack: "攻击",
    rea:"精通"
}

// 比例按照圣遗物副词提比例

let attack_q = 5.8 //5.8   12.7
let criticalRate_q = 3.9
let criticalCtrike_q = 7.8
let dmgAdd_q = 5.8   // 物理角色是 7.2562
let rea_q = 23;
let reaRate = 1.5;

let base = 922  // 白值                                            // 修改这里
let fix_att = 311 + 178 - 0.32// 固定攻击
let att_rate = 106 // 百分比攻击                                           
let criticalRate = 48.6 + 20 // 暴击                                         // 修改这里
let criticalCtrike = 212  // 暴伤                                          // 修改这里
let dmgAdd = 52 + 46.6 + 35 // 增伤                                          // 修改这里
let rea = 141;  // 精通
let reaadd = 0;   // 精通倍率增加
let reaDmgAdd = reaRate * (((278*rea/(rea+1400)) / 100) + 1 + reaadd);
if(reaRate == 1) {
    reaDmgAdd = 1;
}
let kf = reduceResistanceK(10) * lvSuppressK(81, 87);

let rateS = [
    // { rate: 3.6992 },
    { rate: 3.9168 }
]

// let rateS = [
//     { rate: 10.77 },
//     { rate: (0.7524 + 0.738) * 3 + (0.7393 + 0.738) * 3 + (0.9052 + 0.738) * 3 + (0.5195 + 0.738) * 3 + (0.521 + 0.738) * 3 + (1.2436 + 0.738) * 3 }
// ]

    // let attack = 3645;  // 攻击力                                           // 修改这里
    
    rateS.forEach(item => {
        let attack = base * (1 + (att_rate/100))  +  fix_att;  // 攻击力
        console.log(`初始攻击力：${attack}   
        数学期望${item.rate*kf* attack * (1 + dmgAdd/100) * (1-criticalRate/100+criticalRate/100*(1+criticalCtrike/100)) * reaDmgAdd}` + 
        ` 非暴击${attack * (1 + dmgAdd/100) * reaDmgAdd*kf*item.rate}  暴击${attack * (1 + dmgAdd/100) * (1+criticalCtrike/100) * reaDmgAdd*kf*item.rate}`);
    })
   
    let count = 0;
    let flag = false;
    let attack = base * (1 + (att_rate/100))  +  fix_att;  // 攻击力

    (function(){
        count++;
        if(count >= 25 ){return}
        let tmp = [];
        ["attack","criticalRate","criticalCtrike","dmgAdd","rea"].forEach(v=>{
            let qs = {
                "attack": v == "attack" ? 1 : 0, 
                "criticalRate": v == "criticalRate" ? 1 : 0, 
                "criticalCtrike": v == "criticalCtrike" ? 1 : 0, 
                "dmgAdd": v == "dmgAdd" ? 1 : 0,
                "rea": v == "rea" ? 1 : 0,
            }

            
            attack += base*(attack_q * qs.attack / 100); 
            criticalRate += criticalRate_q * qs.criticalRate;
            criticalCtrike += criticalCtrike_q * qs.criticalCtrike;
            dmgAdd += dmgAdd_q * qs.dmgAdd;
            rea += rea_q * qs.rea;
            let tmpCR = criticalRate;
            if(tmpCR > 100) {tmpCR = 100};
            let reaDmgAdd_tmp = reaRate * (((278*rea/(rea+1400)) / 100) + 1 + reaadd);
            if(reaRate == 1) {
                reaDmgAdd_tmp = 1;
            }
            let point = 0;
            rateS.forEach(item => {
                let {rate} = item;
                
                let tmp_point = attack * (1 + dmgAdd/100) * (1-tmpCR/100+tmpCR/100*(1+criticalCtrike/100)) * reaDmgAdd_tmp *kf*rate;

                point += tmp_point
            });

            
            attack -= base*(attack_q * qs.attack / 100); 
            criticalRate -= criticalRate_q * qs.criticalRate;
            criticalCtrike -= criticalCtrike_q * qs.criticalCtrike;
            dmgAdd -= dmgAdd_q * qs.dmgAdd;
            rea -= rea_q * qs.rea;
            tmp.push({point, key:v})
        })
        tmp.sort((a,b) => b.point-a.point);
        if(tmp[0].key == "attack") {
            attack += base*(attack_q / 100); 
        } else if (tmp[0].key == "criticalRate") {
            criticalRate += criticalRate_q ;
        } else if (tmp[0].key == "criticalCtrike") {
            criticalCtrike += criticalCtrike_q ;
        } else if (tmp[0].key == "dmgAdd") {
            dmgAdd += dmgAdd_q ;
        } else if (tmp[0].key == "rea") {
            rea += rea_q ;
        }
        
        console.log("基础期望输出  "+tmp[0].point.toFixed(2) + "   缺少" + enmus[tmp[0].key] + " " + count);
        
        if(flag){
            arguments.callee()
        } else {
            flag = tmp[0].key
            arguments.callee()
        }
    })()




function lvSuppressK(youLv=0, eLv=0, td){
    return (100+youLv)/(100+youLv+(100+eLv)*(td? (100-td)/100 : 1))
}

function reduceResistanceK (resistance) {
    if(resistance < 0) {
        return 1 - resistance/200
    } else if (resistance >=0 && resistance < 75){
        return 1 - resistance/100
    } else {
        return 1/(1+resistance/100*4)
    }
}